import 'package:baselib/utils/color_base_util.dart';
import 'package:baselib/utils/image_util.dart';
import 'package:baselib/utils/navigator_util.dart';
import 'package:baselib/utils/px_base_util.dart';
import 'package:baselib/utils/string_base_util.dart';
import 'package:baselib/widgets/gradient_card_view.dart';
import 'package:flutter/material.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/widgets/page_widget.dart';

import 'comm_widget_manager.dart';

class InviteOnMicGradientDialog extends Dialog {
  String message;
  String icon;

  String negativeText;
  String positiveText;
  Function onCloseEvent;
  Function onPositivePressEvent;
  bool isTouchOutSideDissmiss;
  bool isTouchKeyBackDissmiss;

  InviteOnMicGradientDialog({
    Key key,
    @required this.message,this.icon,
    this.negativeText,
    this.positiveText,
    this.onPositivePressEvent,
    this.isTouchOutSideDissmiss = true,
    this.isTouchKeyBackDissmiss = true,
    @required this.onCloseEvent,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () {
        if (isTouchKeyBackDissmiss) {
          Navigator.of(context).pop();
        }
      },
      child: GestureDetector(
        onTap: () {
          if (isTouchOutSideDissmiss) {
            Navigator.of(context).pop();
          }
        },
        child: new Material(
          type: MaterialType.transparency,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Stack(
                children: [
                  _buildMiddleContUi(),
                  Positioned(
                      left: (PxUtil.instance.screenWidth/2)-PxUtil.instance.px_40,
                      child: _buildPortraitContUi()
                  ),
                ],
              )
            ],
          ),
        ),
      ),
    );
  }

  _buildMiddleContUi() {
    return GradientCardView(
      elevation: PxBaseUtil().px_0,
      margin: EdgeInsets.only(
        top: PxBaseUtil().px_40,
        left: PxBaseUtil().px_30,
        right: PxBaseUtil().px_30,
      ),
      padding: EdgeInsets.only(),
      borderRadius: BorderRadius.circular(PxBaseUtil().px_20),
      child: Container(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(PxBaseUtil().px_20),
          color: ColorBaseUtil().color_2F4072,
        ),
        padding: EdgeInsets.only(
          left: PxBaseUtil().px_35,
          right: PxBaseUtil().px_35,
          top: PxBaseUtil().px_30,
          bottom: PxBaseUtil().px_30,
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              margin: EdgeInsets.only(
                top: PxUtil.instance.px_30
              ),
              child: Text(
                message??'',
                textAlign: TextAlign.center,
                style: TextStyle(
                    color: ColorBaseUtil().color_white,
                    fontSize: PxBaseUtil().px_17),
              ),
            ),
            SizedBox(
              height: PxBaseUtil().px_35,
            ),
            Container(
              child: Row(
                children: [
                  Expanded(
                      child: GestureDetector(
                        onTap: () {
                          if (onCloseEvent != null) onCloseEvent();
                        },
                        child: GradientCardView(
                            elevation: PxBaseUtil().px_0,
                            borderRadius: BorderRadius.circular(
                                PxBaseUtil().px_18),
                            child: Container(
                              height: PxBaseUtil().px_35,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(
                                    PxBaseUtil().px_18),
                                color:
                                ColorBaseUtil().color_transparent,
                              ),
                              child: Center(
                                child: Text(
                                  negativeText ??
                                      StringBaseUtil().Cancel,
                                  style: TextStyle(
                                      color:
                                      ColorBaseUtil().color_white,
                                      fontSize: PxBaseUtil().px_14),
                                ),
                              ),
                            )),
                      )),
                  SizedBox(
                    width: PxBaseUtil().px_30,
                  ),
                  Expanded(
                      child: GestureDetector(
                        onTap: ()=>NavigatorUtil.goBack(),
                        child: GradientCardView(
                            elevation: PxBaseUtil().px_0,
                            borderRadius: BorderRadius.circular(
                                PxBaseUtil().px_18),
                            child: Container(
                              height: PxBaseUtil().px_35,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(
                                    PxBaseUtil().px_18),
                                color: ColorBaseUtil().color_2F4072,
                              ),
                              child: Center(
                                child: Text(
                                  positiveText ??
                                      StringBaseUtil().Confirm,
                                  style: TextStyle(
                                      color: ColorBaseUtil()
                                          .color_white,
                                      fontSize: PxBaseUtil().px_14),
                                ),
                              ),
                            )),
                      )
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  _buildPortraitContUi() {
    return GradientCardView(
        elevation: PxBaseUtil().px_0,
        borderRadius: BorderRadius.circular(
            PxBaseUtil().px_40),
        child: Container(
            height: PxBaseUtil().px_80,
            width: PxBaseUtil().px_80,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(
                  PxBaseUtil().px_40),
              color:
              ColorBaseUtil().color_transparent,
            ),
            child:
            CommWidgetManager.buildCicleImagWidget(
              icon ?? '',
              placeholder: DrawableUtil.instance.icon_default_head,
              width: PxUtil.instance.px_80,
              height: PxUtil.instance.px_80,
              roundRadius: PxUtil.instance.px_40,
              backgroundColor: ColorUtil.instance.color_f2f2f2,
              padding: EdgeInsets.only(),
              margin: EdgeInsets.only(),
            )
        ));
  }
}
